package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.CommonRouteDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RouteInfoDto;
import com.enjoyor.soa.traffic.api.dto.tsms.TaskInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IRouteInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/route" })
@Api("RouteInfoController相关api")
@CrossOrigin
public class RouteInfoController {
	@Autowired
	private IRouteInfoConsumeService iRouteInfoConsumeService;

	/**
	 * 获取线路信息分页；
	 * @return zyh
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@GetMapping(value = { "/getRouteInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("线路信息分页")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "routeName", value = "线路名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "routeStartPlace", value = "起始位置名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "routeTargetPlace", value = "终止位置名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "routeTypeId", value = "类型编号", paramType = "query", dataType = "String")})
	public ResultPojo getRouteInfoPage(
			@RequestParam(defaultValue = "",value="routeId",required=false) String routeId,
			@RequestParam(defaultValue = "",value="routeName",required=false) String routeName,
			@RequestParam(defaultValue = "",value="taskId",required=false) String taskId,
			@RequestParam(defaultValue = "",value="routeStartPlace",required=false) String routeStartPlace,
			@RequestParam(defaultValue = "",value="routeTargetPlace",required=false) String routeTargetPlace,
			@RequestParam(defaultValue = "",value="routeTypeId",required=false) String routeTypeId, 
			Page page, HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iRouteInfoConsumeService.getRouteInfoPage(page, routeId, routeName, taskId, routeStartPlace,
				routeTargetPlace, routeTypeId);
		return resultPojo;
	}
	
	/**
	 * 获取线路集合；
	 * @return zyh
	 */
	@GetMapping(value = { "/getRouteInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=RouteInfoDto.class, code = 0, message = "")
    @ApiOperation("线路信息List查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeName", value = "线路名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeStartPlace", value = "起始位置名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeTargetPlace", value = "终止位置名称", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "routeTypeId", value = "类型编号", paramType = "query", dataType = "String")})
	public ResultPojo getRouteInfoList( 
			@RequestParam(defaultValue = "",value="routeId",required=false) String routeId,
			@RequestParam(defaultValue = "",value="routeName",required=false) String routeName,
			@RequestParam(defaultValue = "",value="taskId",required=false) String taskId,
			@RequestParam(defaultValue = "",value="routeStartPlace",required=false) String routeStartPlace,
			@RequestParam(defaultValue = "",value="routeTargetPlace",required=false) String routeTargetPlace,
			@RequestParam(defaultValue = "",value="routeTypeId",required=false) String routeTypeId, 
    		HttpServletRequest request) {
		return iRouteInfoConsumeService.getRouteInfoList(routeId, routeName, taskId, routeStartPlace, routeTargetPlace,
				routeTypeId);
	}
	
	/**
	 * 添加线路；
	 * @return zyh
	 */
	@PostMapping(value = { "/addRouteInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
	"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加线路信息")
	public ResultPojo addRouteInfo(@RequestBody RouteInfoDto routeInfoDto, HttpServletRequest request) {
		return iRouteInfoConsumeService.insertRouteInfo(routeInfoDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 修改线路；
	 * @return zyh
	 */
	@PutMapping(value = { "/editRouteInfo" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改线路信息")
	public ResultPojo editRouteInfo(@RequestBody RouteInfoDto routeInfoDto, HttpServletRequest request) {
		return iRouteInfoConsumeService.editRouteInfo(routeInfoDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除线路信息；
	 * @return
	 */
	@DeleteMapping(value = { "/deleteRouteInfo" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除线路信息")
    @ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo delRltRoutePost(
    		@RequestParam(defaultValue = "",value="routeId", required=true) String routeId,
    		HttpServletRequest request) {
        return iRouteInfoConsumeService.deleteRouteInfo(routeId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 线路类型切换（备用切换为执行线路）
	 * 
	 */
	@PutMapping(value = { "/changeRouteType" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("线路类型切换（备用切换为执行线路）")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "taskId", value = "任务编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routeId", value = "备用线路编号", paramType = "query", dataType = "string")})
    public ResultPojo changeRouteType(@RequestParam(defaultValue = "") String taskId,
			@RequestParam(defaultValue = "") String routeId, HttpServletRequest request) {
        return iRouteInfoConsumeService.changeRouteType(taskId,routeId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 当天待执行方案进度；
	 * @return zyh
	 */
	@GetMapping(value = { "/getRouteProcress" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=RouteInfoDto.class, code = 0, message = "")
    @ApiOperation("当天待执行方案进度线路List查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "schemeId", value = "方案编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "executeDate", value = "当前执行时间", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "taskName", value = "任务名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "beforeLicensePlate", value = "起始位置名称", paramType = "query", dataType = "string")})
	public ResultPojo getRouteProcress( 
			@RequestParam(defaultValue = "") String schemeId,
			@RequestParam(defaultValue = "") String executeDate,
			@RequestParam(defaultValue = "") String taskName,
			@RequestParam(defaultValue = "") String beforeLicensePlate,
    		HttpServletRequest request) {
		return iRouteInfoConsumeService.getRouteProcress(executeDate, taskName, beforeLicensePlate, schemeId);
	}
	
	
}
